/**********************************************************************************************************************
 *
 * Project:    mGameEngine
 * File:       soundloader.cpp
 * Author:     karooolek
 * Created on: 2009-07-15
 *
 **********************************************************************************************************************/

#include "soundloader.h"
#include "wavloader.h"

namespace mGameEngine
{

namespace Audio
{

Sound *SoundLoader::loadSoundFromFile(const String &filename)
{
    SoundLoader loader(filename);
    loader.load();
    return loader.getSound();
}

SoundLoader::SoundLoader() : SoundFactory(), FileLoader()
{
}

SoundLoader::SoundLoader(const String &filename) :
    SoundFactory(), FileLoader(filename)
{
}

SoundLoader::~SoundLoader()
{
}

void SoundLoader::load()
{
    // begin loading
    _state = 0.0f;

    if(_extension == "wav")
    {
        WAVLoader loader(_filename);
        loader.load();
        _sound = loader.getSound();
    }
    else
    {
        return;
    }

    // end loading
    _state = 1.0f;
}

void SoundLoader::unload()
{
    // no sound
    if(!_sound)
    {
        _state = 0.0f;
        return;
    }

    // unload sound
    delete _sound;

    // end unloading
    _state = 0.0f;
}

}
}

